/**
 * @projectName study-note
 * @package Composite
 * @className Composite.ConcreteDepartment
 */
package Composite;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * ConcreteDepartment
 * @description 具体部门
 * @author answer_wx
 * @date 2022/7/4 10:23
 * @version 1.0
 */
public class ConcreteDepartment extends Department {
    private List<Department> children = new ArrayList<>();

    public ConcreteDepartment(String name) {
        super(name);
    }

    @Override
    public void add(Department d) {
        children.add(d);
    }

    @Override
    public void remove(Department d) {
        children.remove(d);
    }

    @Override
    public void display(int depth) {
        StringBuilder stringBuilder = new StringBuilder();
        int i = depth;
        while (i > 0) {
            stringBuilder.append("-");
            i--;
        }
        System.out.println(stringBuilder + getName());
        for (Department d : children) {
            d.display(depth + 1);
        }
    }

}